package uebungsblatt09.aufgabe17;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

public class MyTableModel extends AbstractTableModel
{
  private static final long serialVersionUID = 8255903293392887351L;
  
  private ArrayList<String> entries;
  
  private static final int DEFAULT_ROWCOUNT = 25;
  private static final int DEFAULT_COLLUMNCOUNT = 2;
  
  public MyTableModel()
  {
    entries = new ArrayList<String>();
  }
  
  public String getColumnName(int column)
  {
    if(column == 0)
      return "Nr";
    else
      return "Event";
  }

  public int getColumnCount()
  {
    return DEFAULT_COLLUMNCOUNT;
  }

  public int getRowCount()
  {
    if(entries.size() > DEFAULT_ROWCOUNT)
      return entries.size();
    return DEFAULT_ROWCOUNT;
  }

  public Object getValueAt(int rowIndex, int columnIndex)
  {
    if(rowIndex >= entries.size())
      return null;
    
    if(columnIndex == 0)
      return rowIndex+1;
    else
      return entries.get(rowIndex);
  }
  
  public void addEntry(String entry)
  {
    entries.add(entry);
  }
  
}
